package com.plant.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.plant.service.FuzzySearchService;


@Controller
@RequestMapping(value = "/hot")
public class HotPeopleContraller {
	@Resource(name = "fuzzySearchServiceImpl")
	private FuzzySearchService fuzzySearchService;

	@RequestMapping(value = "hot_people")//问答达人
	@ResponseBody
	public Map<String, Object> HotPeople(String secret,String pust_val){
		Map<String,Object> map=new HashMap<String, Object>();
		if(secret==null||pust_val==null){
			map.put("state", "0");
			map.put("message", "参数为空");
			return map;
		}else{
			String mdc=Md.MdSecret(pust_val+"flower_duigu2016");
			if(secret.endsWith(mdc)){
				List<Map<String, Object>> weeklist=new ArrayList<Map<String,Object>>();
				List<Map<String, Object>> monthlist=new ArrayList<Map<String,Object>>();
				weeklist=fuzzySearchService.HotWeekPeople();
				monthlist=fuzzySearchService.HotMonthPeople();
				map.put("hot_weeklist", weeklist);
				map.put("hot_monthlist", monthlist);
				map.put("exceed_people", 255);
				map.put("ranking", 355);
				map.put("message", "请求成功");
				map.put("state", "1");
				return map;
			}else{
				map.put("state", "0");
				map.put("message", "秘钥错误");
				return map;
			}
		}
	}
	
	
	@RequestMapping(value = "active_people")//活跃达人
	@ResponseBody
	public Map<String, Object> ActivePeople(String secret,String pust_val){
		Map<String,Object> map=new HashMap<String, Object>();
		if(secret==null||pust_val==null){
			map.put("state", "0");
			map.put("message", "参数为空");
			return map;
		}else{
			String mdc=Md.MdSecret(pust_val+"flower_duigu2016");
			if(secret.endsWith(mdc)){
				List<Map<String, Object>> userinf=new ArrayList<Map<String,Object>>();
				userinf=fuzzySearchService.ActivePeople();
				for (Map<String, Object> map2 : userinf) {
					map2.remove("COUNT(DISTINCT a.user_id)");
				}
				map.put("message", "请求成功");
				map.put("userinf", userinf);
				map.put("state", "1");
				return map;
			}else{
				map.put("state", "0");
				map.put("message", "秘钥错误");
				return map;
			}
		}
	}
	
}
